#!/bin/sh
# This regression test is a part of SIPp.
# The closing scenario screen has its RTP line, not the sockets line
# again, when no time has passed since the screen was last drawn.
. "`dirname "$0"`/../functions"; init

sippbg -sn uas -i 127.0.0.1 -p 5070 -m 1
out=`sippfg -sn uac -i 127.0.0.1 -p 5071 -m 1 127.0.0.1:5070 \
    -timeout 6 -timeout_error 2>&1`
status=$?
screen=`echo "$out" | sed -n '/Scenario Screen/,/Test Terminated/p' | sed -n '/Scenario Screen/h;/Scenario Screen/!H;${x;p;}'`
sockets=`echo "$screen" | grep -c 'open sockets'`
rtp=`echo "$screen" | grep -c 'Total RTP pckts sent'`

if test $status -ne 0; then
    fail "UAC failed with $status"
elif test $sockets -ne 1; then
    fail "$sockets 'open sockets' lines on the closing screen"
elif test $rtp -gt 1; then
    fail "$rtp RTP lines on the closing screen"
else
    ok
fi
